home *** CD-ROM | disk | FTP | other *** search
- //: C21:MemFun2.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // Applying pointers to member functions
- #include <algorithm>
- #include <vector>
- #include <iostream>
- #include <functional>
- using namespace std;
-
- class Angle {
- int degrees;
- public:
- Angle(int deg) : degrees(deg) {}
- int mul(int times) {
- return degrees *= times;
- }
- };
-
- int main() {
- vector<Angle> va;
- for(int i = 0; i < 50; i += 10)
- va.push_back(Angle(i));
- int x[] = { 1, 2, 3, 4, 5 };
- transform(va.begin(), va.end(), x,
- ostream_iterator<int>(cout, " "),
- mem_fun_ref(&Angle::mul));
- cout << endl;
- } ///:~
-